﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;
using System.Configuration.Install;


namespace ClassBuilderWizard
{
    [RunInstaller(true)]
    public partial class DevEnvSetupInstaller : Installer
    {
        public DevEnvSetupInstaller()
        {
            InitializeComponent();
        }

        public override void Install(IDictionary stateSaver)
        {
            //string vs05 = stateSaver["Install2005"] as string;
            //string vs08 = stateSaver["Install2008"] as string;

            RunProcess();
            base.Install(stateSaver);
        }

        public override void Uninstall(IDictionary savedState)
        {
            RunProcess();
            base.Uninstall(savedState);
        }

        private void RunProcess()
        {
            string path = RegistryHelper.GetVSInstallPathFromRegistry(@"SOFTWARE\Microsoft\VisualStudio\8.0");
            path += "IDE\\devenv.exe";

            if (System.IO.File.Exists(path))
            {
                devenv.StartInfo.FileName = path;
                devenv.Start();
                devenv.WaitForExit();
            }

            path = RegistryHelper.GetVSInstallPathFromRegistry(@"SOFTWARE\Microsoft\VisualStudio\9.0");
            path += "IDE\\devenv.exe";

            if (System.IO.File.Exists(path))
            {
                devenv.StartInfo.FileName = path;
                devenv.Start();
                devenv.WaitForExit();
            }

        }
    }
}
